<script type="text/javascript" src="../script/AJAX.js"></script>
<script type="text/javascript" src="../script/notif.js"></script>
<?php
    include_once '../connection/databaseHandler.php';
    $database = new DatabaseHandler();

    $action = $_GET['act'];
    $follower = $_GET['follower'];
    $following = $_GET['following'];
    $date = date("Y-m-d");

    if ($action=="f") {
        $query = "INSERT INTO ".$database->t_notif."(username,message) VALUE ('".$following."','".$follower." is now following you')";
        $database->execQuery($query);
        $query =
        "INSERT INTO ".$database->t_follow."(
            username,
            follow,
            follow_date
        ) VALUES (
            '".$follower."',
            '".$following."',
            '".$date."'
        )";

        if (!$database->execQuery($query)) {
            // gagal follow
        }
        header("location:../profile.php?id=".$following);
    }
    else {
        $query = "INSERT INTO ".$database->t_notif."(username,message) VALUE ('".$following."','".$follower." is not following you anymore')";
        $database->execQuery($query);
        $query =
        "DELETE FROM ".$database->t_follow." WHERE username='".$follower."' AND follow='".$following."'";

        if (!$database->execQuery($query)) {
            // gagal follow
        }
        header("location:../profile.php?id=".$following);
    }  
?>
